﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using PServiceBus.Core.Interface;
using Phoenix.ReflectionExtensions;
using PServiceBus.Core.Runtime;
using PServiceBus.Core.Logger;

namespace PServiceBus.Core.Configuration {
    internal class SubscriptionManagerElement : ConfigurationElement, ISubscriptionManagerConfig {
        public SubscriptionManagerElement() { }
        public SubscriptionManagerElement(string name) { Name = name; }
        [ConfigurationProperty("name", IsRequired = true, IsKey = true)]
        public string Name {
            get { return base["name"] as string; }
            set { base["name"] = value; }
        }
        [ConfigurationProperty("address", IsRequired = true)]
        public string Address {
            get { return base["address"] as string; }
            set { base["address"] = value; }
        }
        [ConfigurationProperty("type", IsRequired = true)]
        public string Type {
            get { return base["type"] as string; }
            set { base["type"] = value; }
        }
    }
    [ConfigurationCollection(typeof(SubscriptionManagerElement), CollectionType = ConfigurationElementCollectionType.BasicMap)]
    internal sealed class SubscriptionManagerCollection : ConfigurationElementCollection {
        protected override ConfigurationElement CreateNewElement() {
            return new SubscriptionManagerElement();
        }

        protected override object GetElementKey(ConfigurationElement element) {
            return (element as SubscriptionManagerElement).Name;
        }
    }
    public sealed class SubscriptionManagerConfigSection : ConfigurationSection {
        [ConfigurationProperty("managers", IsDefaultCollection = true, IsRequired = true)]
        internal SubscriptionManagerCollection Managers {
            get { return this["managers"] as SubscriptionManagerCollection; }
        }
    }
}
